function load_maps()

	world = love.physics.newWorld(0,0, true)

	space_tile = 1
	wall_tile = 2
	floor_tile = 3
	wall_damaged_tile = 4
	med_wall = 5
	med_floor = 6

	map = {}

	map[1] = {
		name = "sleepdeck",
		floor_type = floor_tile,
		lit = false,
		visited = false,
		map_x = -3, -- player starting x/y minus view_center_x/y
		map_y = -1,
		deck = "E",
		id = 1,
		layout = {
			   -- 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
		--[[1]] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[2]]	{ 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[3]] { 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[4]] { 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[5]]	{ 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[6]]	{ 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1 },
		--[[7]]	{ 1, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1 },
		--[[8]]	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 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 1, 1, 1, 1 },
		--[[28]]{ 1, 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 1, 1, 1, 1 },
		--[[29]]{ 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1 },
		--[[30]]{ 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1 },
		--[[31]]{ 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1 },
		--[[32]]{ 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1 },

		},

		features = {

			
			start = { x = 4, y = 4},
			exits = { 	
						{ x = 14, y = 22, dest = 'MedBay' },
						{ x = 15, y = 22, dest = 'MedBay' },
					}, 
			-- dest is id/tableid of where it leads



		},

		items = {

			{ item_type = "health stim", x = 8, y = 5 },
			{ item_type = "health stim", x = 9, y = 5 },

		},

		scourge = {
			{x = 4, y = 15},
			{x = 4, y = 22},
			{x = 4, y = 23},
			{x = 4, y = 24},
			{x = 4, y = 25},
			{x = 4, y = 26},
			{x = 4, y = 27},
			{x = 4, y = 28},
			{x = 4, y = 29},
			{x = 4, y = 30},
			{x = 5, y = 12},
			{x = 5, y = 13},
			{x = 5, y = 17},
			{x = 5, y = 18},
			{x = 5, y = 19},
			{x = 5, y = 20},
			{x = 5, y = 30},
			{x = 6, y = 12},
			{x = 6, y = 30},
			{x = 7, y = 12},
			{x = 7, y = 30},
			{x = 8, y = 7},
			{x = 8, y = 8},
			{x = 8, y = 9},
			{x = 8, y = 10},
			{x = 8, y = 12},
			{x = 8, y = 30},
			{x = 9, y = 9},
			{x = 9, y = 10},
			{x = 9, y = 12},
			{x = 9, y = 30},
			{x = 10, y = 7},
			{x = 10, y = 10},
			{x = 10, y = 12},
			{x = 10, y = 30},
			{x = 11, y = 7},
			{x = 11, y = 8},
			{x = 11, y = 30},
			{x = 12, y = 11},
			{x = 12, y = 30},
			{x = 13, y = 11},
			{x = 13, y = 30},
			{x = 14, y = 8},
			{x = 14, y = 9},
			{x = 14, y = 10},
			{x = 14, y = 11},
			{x = 15, y = 24},
			{x = 15, y = 25},
			{x = 15, y = 26},
			{x = 15, y = 27},
			{x = 15, y = 28},
			{x = 15, y = 29},
			{x = 16, y = 10},
			{x = 16, y = 11},
			{x = 16, y = 12},
			{x = 16, y = 29},
			{x = 17, y = 9},
			{x = 17, y = 10},
			{x = 17, y = 11},
			{x = 17, y = 12},
			{x = 17, y = 29},
			{x = 18, y = 10},
			{x = 18, y = 11},
			{x = 18, y = 12},
			{x = 18, y = 29},
			{x = 19, y = 29},
			{x = 20, y = 8},
			{x = 20, y = 9},
			{x = 20, y = 10},
			{x = 20, y = 29},
			{x = 21, y = 8},
			{x = 21, y = 9},
			{x = 21, y = 10},
			{x = 21, y = 11},
			{x = 21, y = 29},
			{x = 22, y = 9},
			{x = 22, y = 10},
			{x = 22, y = 11},
			{x = 22, y = 29},
			{x = 23, y = 29},
			{x = 24, y = 8},
			{x = 24, y = 9},
			{x = 24, y = 29},
			{x = 25, y = 8},
			{x = 25, y = 9},
			{x = 25, y = 10},
			{x = 25, y = 14},
			{x = 25, y = 15},
			{x = 25, y = 16},
			{x = 25, y = 17},
			{x = 25, y = 21},
			{x = 25, y = 22},
			{x = 25, y = 23},
			{x = 25, y = 24},
			{x = 25, y = 25},
			{x = 25, y = 26},
			{x = 25, y = 27},
			{x = 25, y = 28},
			{x = 25, y = 29},
			{x = 26, y = 8},
			{x = 26, y = 9},
			{x = 26, y = 10},
			{x = 26, y = 11},
			{x = 26, y = 12},
			{x = 26, y = 19},





		},
	}

	map[2] = {
		name = "medbay",
		floor_type = med_floor,
		lit = false,
		map_x = 3,
		map_y = 0,
		deck = "D",
		visited = false,
		id = 2,
		layout = {
			   -- 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
		--[[1]] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[2]]	{ 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[3]] { 1, 2, 2, 2, 2, 2, 2, 2, 5, 5, 5, 5, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[4]] { 1, 2, 5, 5, 5, 5, 5, 5, 5, 6, 6, 5, 5, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[5]]	{ 1, 2, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[6]]	{ 1, 2, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[7]]	{ 1, 2, 5, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6, 5, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[8]]	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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[28]]{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[29]]{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[30]]{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[31]]{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		--[[32]]{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },

		},

		features = {

			
			start = { x = 10, y = 5},
			exits = { 	
						{ x = 10, y = 4, dest = 'SleepDeck' },
						{ x = 11, y = 4, dest = 'SleepDeck' },
						{ x = 13, y = 9, dest = 'GeneratedMap' },
					}, 
			-- dest is id/tableid of where it leads



		},

		items = {

			{ item_type = "mop", x = 7, y = 5 },
			--{ item_type = "health stim", x = 9, y = 5 },

		},

		scourge = {

		},
	}



end

function m_get_exits(map)
	local exits = {}
	for i = 1, #map.features.exits do

		exits[#exits+1] = map.features.exits[i]

	end

	if #exits > 0 then return exits else return nil end


end



-- required to light_tiles
function numerate_grid(grid)

	for y = 1, map_h do
		if grid[y] then
			for x = 1, map_w do
				if grid[y][x] then
					grid[y][x].x = x*(tile_size*scale)
					grid[y][x].y = y*(tile_size*scale)

				end

			end
		end

	end

	return grid

end


function light_tiles(grid)

	local tile_grid = {}

	for y = 1, range_y do

		if grid[y+map_y] then
			tile_grid[y] = {}

			for x = 1, range_x do

				if grid[y+map_y][x+map_x] then
					tile_grid[y][x] = {}

					local gX = dOX+(x*(tile_size*scale))+tile_size*scale
					local gY = dOY+(y*(tile_size*scale))+tile_size*scale

					if p_light_beam_collide(gX,gY) then

						local r = additive_range(player_x, player_y,
							gX, gY)
						--print (" r :", r)

						if r < (3*(tile_size*scale)) then

							tile_grid[y][x].lit = true
							tile_grid[y][x].tile = grid[y][x]
						else

							tile_grid[y][x].lit = false
							tile_grid[y][x].tile = grid[y][x]
						end

					else
						tile_grid[y][x].lit = false
						tile_grid[y][x].tile = grid[y][x]

					end

				end

			end

		end

	end

	light_grid(tile_grid)


end

function light_grid(grid)

	for y = 1, map_h do

		for x = 1, map_w do

			if grid[y] then

				if grid[y][x] then

					if grid[y][x].lit == true then
						tile_type_draw(grid[y][x].tile, dOY+(y*(tile_size*scale)), dOX+(x*(tile_size*scale)))
					else

					end

				end

			end

		end

	end

end

function tile_type_draw(tile_type, y, x)

	local tile_types = {
		[space_tile] = function(z) love.graphics.draw(space_img, x, y, 0, scale, scale) end,
		[floor_tile] = function(z) love.graphics.draw(floor_img, x, y, 0, scale, scale) end,
		[wall_tile] = function(z) love.graphics.draw(wall_img, x, y, 0, scale, scale) end,
		[wall_damaged_tile] = function(z) love.graphics.draw(wall_dam_img, x, y, 0, scale, scale) end,

	}

	tile_types[tile_type]()

end



